#!/bin/sh

flip4MacFolder="/Applications/Flip4Mac"

# Create an alias (soft link) to the Preference Pane in the Flip4Mac folder
prefPanesPath="/Library/PreferencePanes"
prefPaneName="Flip4Mac WMV.prefPane"
if [ -d "$prefPanesPath/$prefPaneName" ] ; then 
	/bin/ln -fs "$prefPanesPath/$prefPaneName" "$flip4MacFolder/WMV Upgrade"
fi

# Copy the Users Guide to the Flip4Mac folder (copy instead of creating a symlink because the Finder gets upset)
userGuidePath="/Library/QuickTime/Flip4Mac WMV Export.component/Contents/Resources"
userGuide="Flip4Mac WMV User Guide.pdf"
if [ -f "$userGuidePath/$userGuide" ] ; then 
	/bin/cp -f "$userGuidePath/$userGuide" "$flip4MacFolder/$userGuide"
fi


# Create an entry in the LaunchServices plist to allow mms URLs to go to WMV Player
defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerRoleAll</key><string>net.telestream.wmvplayerapp</string><key>LSHandlerURLScheme</key><string>mms</string></dict>'

# Touch the component and the QueecksTime folder to help QuickTime know that something has changed
qtFolder="/Library/QuickTime/"
qtComponent="Flip4Mac WMV Import.component"
touch "$qtFolder"
if [ -d "$qtFolder$qtComponent" ] ; then
	touch "$qtFolder$qtComponent"
fi

# Tell the user that that they should quit all QuickTime apps after installing
osascript -e "tell application \"Installer\" to display alert \"You should quit and relaunch all applications that use QuickTime after installing Flip4Mac WMV.\" message \"QuickTime applications cannot take advantage of Flip4Mac WMV features until they are relaunched.\"" ||
osascript -e "tell application \"Installer\" to display dialog \"You should restart your system after installing, and before attempting to use Flip4Mac WMV.\""

# Open the folder containing the newly installed apps, user guide, and all that
open "$flip4MacFolder"

exit 0
